import React, { PureComponent } from 'react'

export default class App extends PureComponent {
  constructor(props) {
    super(props)

    this.state = {
      fruit: 'apple'
    }
  }

  render() {
    return (
      <div>
        {/* 受控组件 */}
        <form onSubmit={e => this.handleSubmit(e)}>
          <label htmlFor="username">
            <select name="fruits" onChange={e => this.handleChange(e)} value={ this.state.fruit }>
              <option value="apple">Apple</option>
              <option value="banana">Banana</option>
              <option value="orange">Orange</option>
            </select>
          </label>
          <input type="submit" value="提交" />
        </form>
      </div>
    )
  }

  handleSubmit(event) {
    event.preventDefault()
    console.log(this.state.fruit)
  }

  handleChange(event) {
    this.setState({
      fruit: event.target.value
    })
  }
}

